#!/bin/bash

# 更新软件包列表
sudo apt update -y

# 安装依赖工具
sudo apt install -y curl lsb-release gpg

# 添加Containerd的GPG密钥
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

# 添加Docker存储库
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# 更新软件包列表
sudo apt update -y

# 安装Containerd
sudo apt install -y containerd.io

# 创建并配置Containerd的系统服务文件
sudo mkdir -p /etc/systemd/system/containerd.service.d/
cat <<EOL | sudo tee /etc/systemd/system/containerd.service.d/override.conf
[Service]
ExecStart=
ExecStart=/usr/bin/containerd
EOL

# 重新加载systemd守护进程配置
sudo systemctl daemon-reload

# 启动Containerd服务
sudo systemctl start containerd

# 设置Containerd在系统启动时自动启动
sudo systemctl enable containerd

# 输出安装结果
echo "Containerd已成功安装并启动。"